package cn.weforward.task.weforward.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import cn.weforward.protocol.doc.annotation.DocAttribute;
import cn.weforward.protocol.doc.annotation.DocObject;

@DocObject(description = "bug分析视图")
public class BugsAnalyzeView {
	
	protected List<String> testers;//测试人
	protected List<String> handlers;//处理人
	protected List<Integer> testerCount;//;//每个测试人测试bug的数目，索引与testers对应
	protected List<Integer> handlersCount;//;//每个测试人测试bug的数目，索引与testers对应
	protected List<String> state;//状态
	protected List<Integer> stateCount;//每个状态的数量
	protected int count;//总数
	protected int finishCount;//已完成的bug数
	
	public BugsAnalyzeView(HashMap<String, Integer> bugsMap) {
		// 将map转换为List
		testers = new ArrayList<String>();
		handlers = new ArrayList<String>();
		testerCount = new ArrayList<Integer>();
		handlersCount = new ArrayList<Integer>();
		state = new ArrayList<String>();
		stateCount = new ArrayList<Integer>();
		
		Set<Entry<String, Integer>> set = bugsMap.entrySet();
		Iterator<Entry<String, Integer>> it = set.iterator();
		
		while(it.hasNext()) {
			Entry<String, Integer> entry = it.next();
			//如果t开头，代表是测试人
			if(entry.getKey().startsWith("t")) {
				//去掉开头的t字母，添加该测试人名字
				testers.add(entry.getKey().substring(1));
				//添加该测试人测试bug数
				testerCount.add(entry.getValue());
			}
			//如果h开头，代表是测试人
			if(entry.getKey().startsWith("h")) {
				//去掉开头的h字母，添加该处理人名字
				handlers.add(entry.getKey().substring(1));
				//添加该处理人处理bug数
				handlersCount.add(entry.getValue());
			}
			//如果s开头，代表是状态
			if(entry.getKey().startsWith("s")) {
				//去掉开头的s字母，添加该处理人名字
				state.add(entry.getKey().substring(1));
				//添加该状态的数量
				stateCount.add(entry.getValue());
			}
		}
		count = bugsMap.get("bug总数");
		finishCount = bugsMap.get("已完成bug数");
	}
	
	@DocAttribute(description = "bugs测试人")
	public List<String> getTesters() {
		return testers;
	}
	@DocAttribute(description = "每个测试人测试出的bug数")
	public List<Integer> getTesterCount() {
		return testerCount;
	}
	@DocAttribute(description = "bugs处理人")
	public List<String> getHandlers() {
		return handlers;
	}
	@DocAttribute(description = "每个处理人处理的bug数")
	public List<Integer> getHandlerCount() {
		return handlersCount;
	}
	@DocAttribute(description = "bugs状态")
	public List<String> getStates() {
		return state;
	}
	@DocAttribute(description = "每个状态的数量")
	public List<Integer> getStateCount() {
		return stateCount;
	}
	@DocAttribute(description = "bug总数")
	public int getCount() {
		return count;
	}
	@DocAttribute(description = "已完成bug数")
	public int getFinishCount() {
		return finishCount;
	}
}
